<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!--Hier fuegt man seinen Arbeitsgeber  oder Firmennamen ein und beschreibt von wann bis wann man in der Firma gearbeitet hat... -->
<%String file="./index.jsp?"+Constant.CONTENT+"="+Constant.activity, method="get"; %>
<%@page import="db.DBMain"%>
<%RequestParser.send_action_file=file;
RequestParser.send_method=method;%>
<%@include file="town.jsp" %>
<%@page import="html.RequestParser"%>
<%@page import="db.tables.DBTypeTable"%>
<%@page import="java.sql.Date"%>
<%@page import="db.tables.DBActivityTable"%>
<%@page import="db.tables.reference.DBIsActiveTable"%>
<script type="text/javascript"><!--

<%
Long type_id_temp=DBMain.getTypeTable().selectLong(DBTypeTable.TYPE_ID_COL,DBTypeTable.TYPE_NAME_COL,Constant.Type.ACTIVITY),
	user_id=0L, cat_id=RequestParser.getLongFromParameter(request,Constant.Content.CATEGORY);//session.getAttribute(Constant.USERID);
session.setAttribute(Constant.Content.TYPE,type_id_temp);

RequestParser activityParser=new RequestParser(request,file,method);
activityParser.setAdd(Constant.Content.ADD_ACTIVITY);
activityParser.setContent(Constant.Content.ACTIVITY);
activityParser.setSubmit(Constant.Content.SUBMIT_ACTIVITY);
activityParser.setDelete(Constant.Content.DELETE_ACTIVITY);
activityParser.setInput(new String[]{Constant.Content.INPUT_ACTIVITY,Constant.Content.TOWN,Constant.Content.CATEGORY});
activityParser.setInsert_columns(new String[]{DBActivityTable.ACTIVITY_NAME_COL,DBActivityTable.TOWN_ID_COL,DBActivityTable.CATEGORY_ID_COL});
activityParser.setDisplay_columns(new String[]{DBActivityTable.ACTIVITY_ID_COL,DBActivityTable.ACTIVITY_NAME_COL,DBActivityTable.CATEGORY_ID_COL});
activityParser.setPk_column(DBActivityTable.ACTIVITY_ID_COL);
activityParser.setTable(DBMain.getActivityTable());
activityParser.setFk_columns(new String[]{DBActivityTable.TOWN_ID_COL,DBActivityTable.CATEGORY_ID_COL});
activityParser.setFk_ids(new Long[]{town_id,cat_id});
activityParser.process();

RequestParser isActiveParser=new RequestParser(request,file,method);
isActiveParser.setAdd(Constant.Content.ADD_ACTIVITY_MEMBER);
isActiveParser.setContent(Constant.Content.ACTIVITY_MEMBER);
isActiveParser.setSubmit(Constant.Content.SUBMIT_ACTIVITY_MEMBER);
isActiveParser.setDelete(Constant.Content.DELETE_ACTIVITY_MEMBER);
isActiveParser.setInput(new String[]{Constant.Content.ACTIVITY,Constant.Content.INPUT_START,Constant.Content.INPUT_END});
isActiveParser.setInsert_columns(new String[]{DBIsActiveTable.USER_ID_COL,DBIsActiveTable.ACTIVITY_ID_COL,DBIsActiveTable.START_DATE_COL,DBIsActiveTable.END_DATE_COL});
isActiveParser.setDisplay_columns(new String[]{DBIsActiveTable.IS_ACTIVE_ID_COL,DBIsActiveTable.START_DATE_COL,DBIsActiveTable.END_DATE_COL});
isActiveParser.setPk_column(DBIsActiveTable.IS_ACTIVE_ID_COL);
isActiveParser.setTable(DBMain.getIsActiveTable());
isActiveParser.setFk_column(DBIsActiveTable.USER_ID_COL);
isActiveParser.setFk_id(user_id);
isActiveParser.setPk_id(RequestParser.getLongFromParameter(request, isActiveParser.getContent()));

	if(admin) {
		if (request.getParameter(isActiveParser.getSubmit()) != null) {
			if (RequestParser.areAllParametersNotNull(request, isActiveParser.getInput())) {
				int i=0;
				String[] req=isActiveParser.getInput();
				Object[] result = new Object[req.length+1];
				//DBIsActiveTable.USER_ID_COL 
				result[i]=user_id;
				//DBIsActiveTable.ACTIVITY_ID_COL
				i++;
				result[i]=Long.parseLong(request.getParameter(Constant.Content.ACTIVITY));
				//DBIsActiveTable.START_DATE_COL,
				i++;
				result[i]=Date.valueOf(request.getParameter(Constant.Content.INPUT_START));
				//DBIsActiveTable.END_DATE_COL 
				i++;
				String t=request.getParameter(Constant.Content.INPUT_END);
				if(t!=null&&!t.equals("")&&!t.equalsIgnoreCase("null"))
					result[i]=Date.valueOf(t);
				else result[i]=null;
				isActiveParser.setPk_id(isActiveParser.getTable().insertGetPK(isActiveParser.getInsert_columns(), result));
			} else if (RequestParser.areSomeParametersNotNull(request, isActiveParser.getInput())) {
				// TODO Error output because only one parameter is set -
				// needed are both!
			}
		}
	}
	// #########################################################
	// FIXME add additional functions so it is i.e. possible to delete
	// only all related towns or vice versa
	// #########################################################
	if(admin) {
		if (request.getParameter(isActiveParser.getDelete()) != null && isActiveParser.getPk_id() != null) {
			isActiveParser.getTable().delete(isActiveParser.getPk_column(), isActiveParser.getPk_id());
		}
	}
	isActiveParser.setArray(isActiveParser.getTable().getSelect(isActiveParser.getDisplay_columns(), new String[]{isActiveParser.getFk_column()}, new Object[]{isActiveParser.getFk_id()}));
%>
//
--></script>
<form name="<%=activityParser.getContent() %>" action="<%=activityParser.getSend_action_file() %>" method="<%=activityParser.getSend_method()%>">
	<%@include file="category_only.jsp" %>
	<select name="<%=Constant.Content.ACTIVITY %>" onchange="submit()">
		<%
			activityParser.printOptionList(out);
		%>
	</select>
          <table width="38%" border="0">
       <tr> 
         <td width="17%">Beginn:</td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_START%>" size="11" value="">
		<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" 
		onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'<%=activityParser.getContent() %>.<%=Constant.Content.INPUT_START%>',true,'yyyy-mm-dd'); return false;">
		<img src="../images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt=""></a>
         </td>
         </tr>
             <tr> 
         <td width="17%">Ende: </td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_END%>" size="11" value="">
		<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" 
		onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'<%=activityParser.getContent() %>.<%=Constant.Content.INPUT_END%>',true,'yyyy-mm-dd'); return false;">
		<img src="../images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt=""></a>
         </td>
         </tr>
             <tr>
         <td width="17%">
         	<input type="hidden" name="<%=Constant.Content.COUNTRY %>" value="<%=country_id %>"/>
			<input type="hidden" name="<%=Constant.Content.TOWN %>" value="<%=town_id %>"/> 
           <input type="submit" name="<%=Constant.Content.SUBMIT_ACTIVITY_MEMBER %>" value="Speichern">
         </td>
         <td width="83%">
           <input type="reset" name="zuruecksetzen" value="Zur&uuml;cksetzen">
         </td>
     </table>
</form>